package com.linkwechat.web.controller.wecom;

import java.util.List;
import java.util.Arrays;

import com.linkwechat.wecom.domain.SysFileInfo;
import com.linkwechat.wecom.service.ISysFileInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.enums.BusinessType;
/*import com.linkwechat.domain.SysFileInfo;
import com.linkwechat.service.ISysFileInfoService;*/
import com.linkwechat.common.utils.poi.ExcelUtil;
import com.linkwechat.common.core.page.TableDataInfo;

/**
 * 文件信息Controller
 * 
 * @author ruoyi
 * @date 2022-01-03
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/linkwechat/info" )
public class SysFileInfoController extends BaseController {

    private final ISysFileInfoService iSysFileInfoService;

    /**
     * 查询文件信息列表
     */
    @PreAuthorize("@ss.hasPermi('linkwechat:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysFileInfo sysFileInfo) {
        startPage();
        List<SysFileInfo> list = iSysFileInfoService.queryList(sysFileInfo);
        return getDataTable(list);
    }

    /**
     * 导出文件信息列表
     */
    @PreAuthorize("@ss.hasPermi('linkwechat:info:export')" )
    @Log(title = "文件信息" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(SysFileInfo sysFileInfo) {
        List<SysFileInfo> list = iSysFileInfoService.queryList(sysFileInfo);
        ExcelUtil<SysFileInfo> util = new ExcelUtil<SysFileInfo>(SysFileInfo.class);
        return util.exportExcel(list, "info" );
    }

    /**
     * 获取文件信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('linkwechat:info:query')" )
    @GetMapping(value = "/{fileId}" )
    public AjaxResult getInfo(@PathVariable("fileId" ) Long fileId) {
        return AjaxResult.success(iSysFileInfoService.getById(fileId));
    }

    /**
     * 新增文件信息
     */
    @PreAuthorize("@ss.hasPermi('linkwechat:info:add')" )
    @Log(title = "文件信息" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysFileInfo sysFileInfo) {
        return toAjax(iSysFileInfoService.save(sysFileInfo) ? 1 : 0);
    }

    /**
     * 修改文件信息
     */
    @PreAuthorize("@ss.hasPermi('linkwechat:info:edit')" )
    @Log(title = "文件信息" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysFileInfo sysFileInfo) {
        return toAjax(iSysFileInfoService.updateById(sysFileInfo) ? 1 : 0);
    }

    /**
     * 删除文件信息
     */
    @PreAuthorize("@ss.hasPermi('linkwechat:info:remove')" )
    @Log(title = "文件信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{fileIds}" )
    public AjaxResult remove(@PathVariable Long[] fileIds) {
        return toAjax(iSysFileInfoService.removeByIds(Arrays.asList(fileIds)) ? 1 : 0);
    }
}
